"use strict";

/**
 * @auther wtfssd
 * Created by wtfssd on 2017/11/15
 */
import * as React from 'react'
import {autoSize, commonStyles} from "../../assets/styles/common";
import MyText from "../../component/MyText";
import Line from "../../component/Line";
import WithDrawListItem from "../../component/WithDrawItem";
import {BalanceComponent, WithDrawItem} from "../../interface/index";

const {View, FlatList} = require('react-native');
const {connect} = require('react-redux');

class WithdrawPage extends React.Component<BalanceComponent, any> {
    onRefresh = ()=>{
        this.props.dispatch({
            type:'balance/fetchWithDrawList'
        })
    };

    renderHeader = () => {
        return (
            <View style={[commonStyles.flexRow, {height: autoSize(46),paddingHorizontal:10}]}>
                <View style={[{display:'flex',flex:0.8,justifyContent:'center'}]}>
                    <MyText>提取时间</MyText>
                </View>
                <View style={[commonStyles.centerVH,{display:'flex',flex:0.2,justifyContent:'center'}]}>
                    <MyText>金额</MyText>
                </View>

            </View>
        )
    };

    render() {
        return (
            <FlatList data={this.props.balance.withDrawList}
                      onRefresh={this.onRefresh}
                      refreshing={this.props.balance.loading}
                      ListHeaderComponent={this.renderHeader}
                      keyExtractor={(item:WithDrawItem) => item.updated_at}
                      ItemSeparatorComponent={()=><Line/>}
                      renderItem={(params:{item:WithDrawItem,index:number}) => <WithDrawListItem {...params.item} key={params.index}/>}/>
        );
    }
}


export default connect(
    ({auth,balance})=>({auth,balance})
)(WithdrawPage);